# 优惠信息详情接口
from curl_cffi import requests

proxies = {
    "http": "127.0.0.1:7890",
    "https": "127.0.0.1:7890",
}
import asyncio
import json
import time

from curl_cffi import requests
import subprocess
from functools import partial

subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import execjs
import hashlib

with open("h5st.js", "r", encoding="utf-8") as f:
    js = f.read()

js_com = execjs.compile(js)


def sha_256(message):
    return hashlib.sha256(message.encode("utf-8")).hexdigest()


def generate_h5st(params):
    # 解析原始 body
    body_str = params["body"]
    body = json.loads(body_str) if isinstance(body_str, str) else body_str

    # 创建用于 SHA256 加密的 boddy
    boddy = {
        "skuId": body["skuId"],
        "cat": body["cat"],
        "area": body["area"],
        "shopId": body["shopId"],
        "venderId": body["venderId"],
        "paramJson": body["paramJson"],
        "num": body["num"],
        "bbTraffic": body["bbTraffic"],
        "canvasType": body["canvasType"],
        "giftServiceIsSelected": body["giftServiceIsSelected"],
        "customInfoId": body["customInfoId"],
        "sfTime": body["sfTime"],
    }

    # 创建用于生成 h5st 的 a 对象
    a = {
        "appid": params.get("appid", "pc-item-soa"),
        "body": sha_256(json.dumps(boddy, separators=(",", ":"))),
        "clientVersion": params.get("clientVersion", "1.0.0"),
        "client": params.get("client", "pc"),
        "functionId": params.get("functionId", "pc_detailpage_wareBusiness"),
        "t": int(time.time() * 1000),  # 使用当前时间戳
    }

    # 调用 JS 的 PSign.sign 方法生成 h5st
    h5st = js_com.call("getH5st", a)

    return h5st


headers = {
    "accept": "application/json, text/javascript, */*; q=0.01",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8,ar;q=0.7",
    "cache-control": "no-cache",
    "origin": "https://item.jd.com",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "referer": "https://item.jd.com/",
    "sec-ch-ua": '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": '"Windows"',
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0",
    "x-referer-page": "https://item.jd.com/10117251496813.html",
    "x-rp-client": "h5_1.0.0",
}
cookies = {
    "b_webp": "1",
    "b_avif": "1",
    "jcap_dvzw_fp": "_HIVLiZCIEZDIcHwXjPU43al5uvsYIwPfs4O6VE9nqABptbi3ASG0seWjzU_o2F4bpTtKrH1VphdN9RwziykSA==",
    "whwswswws": "",
    "__jdu": "1751545604909534518369",
    "pinId": "briEibRb-h1YgxkG81uaz7V9-x-f3wj7",
    "pin": "jd_7eac037a858fc",
    "unick": "jd_8js7q5tn2s7n2h",
    "_tp": "aO5XtogPiplRTZPyN6P5Vkd5JC%2FQJe7kEmh0g0oTaNI%3D",
    "_pst": "jd_7eac037a858fc",
    "shshshfpa": "ab96e4b0-82d6-a907-9206-6c096fe807bb-1751545628",
    "shshshfpx": "ab96e4b0-82d6-a907-9206-6c096fe807bb-1751545628",
    "autoOpenApp_downCloseDate__jd_czlogin_openapp_": "1752224419174_1",
    "b_dw": "1912",
    "b_dh": "954",
    "b_dpr": "1",
    "commonAddress": "0",
    "regionAddress": "1%2C72%2C55674%2C0",
    "autoOpenApp_downCloseDate_autoOpenApp_autoPromptly": "1752227819923_1",
    "autoOpenApp_downCloseDate_jd_homePage": "1752462226750_1",
    "autoOpenApp_downCloseDate_auto": "1752462295553_1800000",
    "pt_st": "1_QNKa_p1pyRBuRGl7XqjS4ZLHq52uvHozXQu0yZZJaZBykE4huAxadU8rhTxkOed5v-IuGcuXOYsk2aIeXaDCbyBsLjrt7MdvOSvBodXxczB1FkZgSNPx2J-jeoajHnfW39S6QiYrPFEIK1rDtYq4I4SRP4BxLa81ywRy9N0XGlJp_KtCaUMwl_dWLrRUp5syXYAGm0trSW0tTUQiv77qSqdfTbhMefstFJyB3qwZ",
    "__jdv": "76161171|direct|-|none|-|1756881433725",
    "TrackID": "1xM3ZQ21DHtuXgiq36XtFIOSXu1mAWZ4x-D5xaVdH7fy-vfDHlmTkQwxI_jvHRLi8LJioNT25c_6PKire-mo6MVOioLX3wONC6NgLWZauD51IyQW3ZNZ5YAfd9rbm-Khp",
    "light_key": "AASBKE7rOxgWQziEhC_QY6ya0t-vlaOmou2BzyMrCts2vOi5coHY-N24rrJkrJnFBW04tveI",
    "3AB9D23F7A4B3C9B": "GNWKXUTIE6HBK6NALGSXSPDIJB4FOSTK2HH5HNAWZAUUMF5JYQCGOIB4252C7TECGDOSXSGLUC74Z5SQVPIKNU2LBE",
    "areaId": "19",
    "ipLoc-djd": "19-1607-4773-62123",
    "thor": "2B3FAB022DDA7FFF772855629D82E8BA86B6B654FC776E1930AA7FEB1EB3100E1EF5EB759739600F22FCCF1958FE9679B0EEA60481F98D5CEF896FE1C118BC6F5902AEA9B671F28B659099323024C59799B63A1868AC8D1579B564EB1C6725F65D3E137CF8D9B3055385727960FA2DB0582E23CEF871A191CC2BC9FB3D0381D0FCB9E5F8F8D6B912AD4BC29B1A5CA075D1A2E963DC5DF26B14C5B056504FE0AC",
    "mail_times": "4%2C1%2C1757399500426",
    "cn": "12",
    "PCSYCityID": "CN_440000_440300_0",
    "mt_xid": "V2_52007VwMUVl1cV14YSBxUBG8HEFdZWFtYGEEpXQRhBUAFWFtODxxLEUAAbgYbTg0NU1IDHRxbUG4FF1AKX1NTL0oYXwF7AhpOXFBDWhpCHVwOZgQiUG1YYl4bSh9VAmQGElVcaFdbFk8%3D",
    "token": "188b4629cff7da2d94fe75fd23e98adb,3,976333",
    "jsavif": "1",
    "3AB9D23F7A4B3CSS": "jdd03GNWKXUTIE6HBK6NALGSXSPDIJB4FOSTK2HH5HNAWZAUUMF5JYQCGOIB4252C7TECGDOSXSGLUC74Z5SQVPIKNU2LBEAAAAMZFU7BKOYAAAAACZRQCEYHSY4Y6MX",
    "_gia_d": "1",
    "__jda": "181111935.1751545604909534518369.1751545604.1756881434.1757399499.20",
    "__jdc": "181111935",
    "flash": "3_mgjEaudo-HHk8lTkU7RLmL7HXGA-4a3KZm2CATriHoGk_cr7Y-ImVmuvxlSdX9cr-Qv7GZFEXDUUvQFVEaYSKyrlJtjcB0AU2Mc5Kol5eH-OXW6adX8r794_ibouLR_L6MBNb7yIZBI97OjQo-NDu0FiAnTtCeo26zOpbNKwwhZs_joe5Hp6Nq**",
    "__jdb": "181111935.9.1751545604909534518369|20.1757399499",
    "shshshfpb": "BApXSjak2LvxAYEqgcJFHsyDPBX7ULrZhBhMVUQdk9xJ1MppMe462",
    "sdtoken": "AAbEsBpEIOVjqTAKCQtvQu17khXQfa7U-cqigDPZYcstdR8eIdex403hCQXUiQps8U5Nd5p9DZvQuAEyWsxKNtgzMWf2NvRiMRx_g40j7QFOW8iCJxZSTww_MTy23CLhKMB1P-JX",
}
url = "https://api.m.jd.com/"
params = {
    "appid": "pc-item-soa",
    "functionId": "pc_detailpage_wareBusiness",
    "client": "pc",
    "clientVersion": "1.0.0",
    "t": "1757400678986",
    "body": '{"skuId":10117251496813,"cat":"6196,6219,6223","area":"19_1607_4773_62123","shopId":"11482845","venderId":11751949,"paramJson":"{\\"platform2\\":\\"1\\",\\"colType\\":0,\\"specialAttrStr\\":\\"p0ppppppppp3pppppppppppppppp\\",\\"skuMarkStr\\":\\"00\\"}","num":1,"bbTraffic":"","canvasType":1,"giftServiceIsSelected":"","customInfoId":"0","sfTime":"1,0,0"}',
    "h5st": "20250909145121034;miazzz3za3j600p8;fb5df;tk03wd4b41cc518nMqgYnPgQb5bBKofktPwB-pxrurDspYOTZ7h8WeHT4tkZD_j5HNk7HFdSMZY33dQxx1ExLS0ahUkf;40fb388bf38d10b281a8e248fcca3fa4;5.2;1757400679034;fZRCXZfTzd_WxZfZnZPVsY7ZBh-f1ZfTxgeVr5rVA4qVn46DA8LG-h-T-h6I-hfZXx-Uwh-T-prJ_YfZB5hW-RrVvNeT_8eItduUp9uU9ULI8UOVph_IthOV7MrVvNuJ-h-T-h6Q1E7J8E6ZBh-f1ZfIqBeU7YuJ8M7IodOU_YbIuZ_IoBeV78uUtdOU9AOVxZfZnZvFAI6GAU7ZBh-f1ZfV-h-T-ROE-YfZB5hW-h_WvpPUrkMI187ICMeH-h-T-J6ZBh-f1ZvPVQqVpY_UvV7ZB5_Z0kbIzc7F-hfZXx-ZvV_G4E8ZB5_Z7g6ZBh-f1taZB5BZ7I9ZB5_ZudOE-YfZBhfZXxvVB5_ZwdOE-YfZBhfZXxfUwh-T-hOVsY7ZBhfZB5hWptfZnZ-VwN6J-hfZBh-f1ZvJ4UuPsIbOuJ6N0I7F-h-T-trG9oLJvYfZBhfZXxfVB5_ZpN6J-hfZBh-f1heZnZvUsY7ZBhfZB5hWoZeZnZ-UsY7ZBhfZB5hWxh-T-NOE-YfZBhfZXxfVB5_ZtN6J-hfZBh-f1VeVwh-T-VOE-YfZBhfZXx-ZopPVzh_ZB5_ZwN6J-hfZBh-f1heZnZvHqYfZBhfZXxPUB5_Zuw7ZBhfZB5hWxh-T-x7ZBhfZB5hWxh-T-RrE-hfZBh-fmg-T-R7G8QaD8YfZB5hWkgfZXZvJ7AOUpdrUuhuJAMrUCQ7H-h-T-ZeF-hfZBh-fmg-T-haF-hfZXx-ZtJeDB1eUrpLHKgvTxpfVwhfMTgvFqkbIz8rM-h-T-dLEuYfZB5xD;cf64559b2c800312972d4e055b72697f;gRaW989Gy8bE_oLE7w-Gy8rFvM7MtoLI4wrJ1R6G88bG_wPD9k7J1RLHxgKJ",
    "x-api-eid-token": "jdd03GNWKXUTIE6HBK6NALGSXSPDIJB4FOSTK2HH5HNAWZAUUMF5JYQCGOIB4252C7TECGDOSXSGLUC74Z5SQVPIKNU2LBEAAAAMZFU7BKOYAAAAACZRQCEYHSY4Y6MX",
    "loginType": "3",
    "scval": "10117251496813",
    "uuid": "181111935.1751545604909534518369.1751545604.1756881434.1757399499.20",
}
response = requests.get(url, headers=headers, cookies=cookies, params=params)

print(response.text)
print(response)
